package com.hhf.springboot.mq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author hhf
 * @Date 2025/6/15
 * @Description
 */
@Configuration
public class RabbitMqConfig {

    /**
     * 创建死信交换机
     * @return
     */
    @Bean
    public DirectExchange deadLetterExchange(){
        return new DirectExchange(BiMqConstant.DEAD_EXCHANGE);
    }

    /**
     * 创建私信队列
     * @return
     */
    @Bean
    public Queue deadLetterQueue(){
        return new Queue(BiMqConstant.DEAD_QUEUE);
    }

    /**
     * 绑定
     * @param deadLetterExchange
     * @param deadLetterQueue
     * @return
     */
    @Bean
    public Binding deadLetterQueueBindingDeadLetterExchange(@Qualifier("deadLetterExchange") DirectExchange deadLetterExchange,
                                                            @Qualifier("deadLetterQueue") Queue deadLetterQueue){
        return BindingBuilder.bind(deadLetterQueue).to(deadLetterExchange).with(BiMqConstant.DEAD_ROUTING_KEY);
    }



}
